import React, { useState }  from 'react';
import './index.less';
import api from '../../axios'
import { Button, Image,
  Descriptions,
  message,
  Switch,
  Popconfirm } from 'antd';



class index extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 
            visible: false,
            loading: true,
            fileloading: false,
            imageUrl: '',
            initialValues: {},
            data: '0',
            editModalVis: false,
        };
    }

    confirm = (e) => {
        message.success('操作成功');
    }


    componentDidMount(){
        this.getData()
    }

    onChange = (checked) => {
        console.log(`switch to ${checked}`);
        this.changeState()
    };

    changeState = async () => {
        let res = await api.ajax({
            method: 'post',
            url: `/config/imgswitch`,
            data: {
                status: this.state.data == '1' ? 0 : 1
            }
        });

        this.getData()

    }
    
    getData = async () => {
      let res = await api.ajax({
          method: 'get',
          url: `/config/imgswitch`,
      });

      this.setState({
          data: res.data.value,
      })
    }

    onOk = () => {

    }
    
    render() {
    
      const { data } = this.state

        return (
           <>
             <div className='wapper'>
                <div>
                  <Descriptions title="首页">
                    <Descriptions.Item label="首页卡片图片是否显示">
                        {
                            data > '0' &&
                            <Switch defaultChecked={true} onChange={() => this.onChange()} />
                        }
                        {
                            data == '0' &&
                            <Switch onChange={() => this.onChange()} />
                        }
                    </Descriptions.Item>
                  </Descriptions>
                </div>
             </div>

           </>
        );
    }
}

export default index;